package com.jy.adscm.operation.aftersales.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.aftersales.bean.BaseQuery;
import com.jy.adscm.operation.aftersales.bean.ShSettingParts;
import com.jy.adscm.operation.aftersales.bean.ShSettingPhenomenon;
import com.jy.adscm.operation.aftersales.mapper.mysql.ShSettingPartsMapper;
import com.jy.adscm.operation.aftersales.service.ShSettingPartsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-08-28
 */
@Service
public class ShSettingPartsServiceImpl extends ServiceImpl<ShSettingPartsMapper, ShSettingParts> implements ShSettingPartsService {
    @Autowired
    JyUserMapper  jyUserMapper;
    @Override
    public Page<ShSettingParts> selectAll(Page<ShSettingParts> page, BaseQuery baseQuery) {
        Wrapper<ShSettingParts> wrapper =new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(baseQuery.getCodition(),null)){
            wrapper.like("name",baseQuery.getCodition());
        }
        page=super.selectPage(page,wrapper);
        List<ShSettingParts> records = page.getRecords();
        for (ShSettingParts shSettingParts : records) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(shSettingParts.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(shSettingParts.getCreator());
                shSettingParts.setCreatorName(jyUser.getName());
            }

        }
        page.setTotal(super.selectCount(wrapper));
        return page;
    }
}
